<template>
  <div>
    <el-dialog
        :title="dialog.title"
        v-model="dialog.visible"
        width="70%"
        append-to-body
        modal-append-to-body
        @close="handleClose">
      <start-act-admin-user-select v-if="taskCandidateConfig.confKey==='custom_auth_candidate'"
                                   ref="userSelect"></start-act-admin-user-select>
      <template #footer>
        <span class="dialog-footer">
            <el-button @click="cancel()">取 消</el-button>
            <el-button @click="clearSelectUser()">清 空</el-button>
            <el-button type="primary" @click="submit">确定</el-button>
          </span>
      </template>
    </el-dialog>
  </div>
</template>

<script>

import StartActAdminUserSelect from "./startActAdminUserSelect.vue";

export default {
  name: "startActSelectUser",
  components: {StartActAdminUserSelect},
  computed: {},
  data() {
    return {
      dialog: {
        visible: false,
        title: '',
      },
      taskCandidateConfig: {}
    }
  },
  methods: {
    show(config, title = '请选择审批人') {
      this.dialog.title = title;
      this.dialog.visible = true;
      this.taskCandidateConfig = config;
    },
    cancel(){
      this.handleClose();
      this.$emit("cancel")
    },
    handleClose() {
      this.dialog.visible = false;
    },
    clearSelectUser() {
      if (!this.$refs.userSelect) {
        return;
      }
      if (!this.$refs.userSelect.clearSelectUser) {
        this.$message.error("子组件未定义清空选择函数：clearSelectUser")
        return
      }
      this.$refs.userSelect.clearSelectUser()
    },
    submit() {
      if (!this.$refs.userSelect.getSelectUsers) {
        this.$message.error("子组件未定义获取已选中函数：getSelectUsers")
        return
      }
      let selectList = this.$refs.userSelect.getSelectUsers();
      if (!selectList || selectList.length < 1) {
        this.$message.error("至少选择一个审批人")
      }
      selectList = JSON.parse(JSON.stringify(selectList))
      const done = () => this.handleClose();
      this.$emit("submit", selectList, done)
    },
  }
}
</script>

<style scoped>

</style>